//
//  DetailCourseRecordVC.m
//  HTT
//
//  Created by admin on 15/12/1.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "DetailCourseRecordVC.h"
#import "CourseRecordV.h"
#import "KnowldgeV.h"
#import "StudentAcessView.h"
#import "ReviewView.h"
#import "ClassCourseViewModel.h"
#import "EvaluationViewController.h"
@interface DetailCourseRecordVC ()<EvaluationVCDelagete>
@property (nonatomic, retain) UIScrollView *backView;
@property (nonatomic, retain) CourseRecordV *view_1;
@property (nonatomic, retain) KnowldgeV *view_2;
@property (nonatomic, retain) ReviewView *view_3;
@property (nonatomic, retain) StudentAcessView *view_4;


@property (nonatomic, retain) CourseRecordDetailModel *courseRecordDetailModel;
@end

@implementation DetailCourseRecordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self _initView];
    [self getViewData];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self addCustomBackBase];
    [self addCustomTitleWithTitle:@""];
    
}
- (UIScrollView *)backView{
    if (!_backView) {
        _backView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeihgt - NavHe)];
        [_backView setBackgroundColor:RGBCOLOR(230, 230, 230, 1)];
        _backView.userInteractionEnabled = YES;
        [_backView setContentSize:CGSizeMake(ScreenWidth, ScreenHeihgt)];
    }
    return _backView;
}
- (void)_initView{
    [self.view addSubview:self.backView];
    _view_1 = [[CourseRecordV alloc] init];
    [self.backView addSubview:_view_1];
    
    _view_2 = [[KnowldgeV alloc] init];
    [self.backView addSubview:_view_2];
    
    _view_3 = [[ReviewView alloc] init];
    [self.backView addSubview:_view_3];
    
    _view_4 = [[StudentAcessView alloc] init];
    [self.backView addSubview:_view_4];
}
- (void)setViewData{
    [_view_1 setViewData:_courseRecordDetailModel];
    
    [_view_2 setViewData:_courseRecordDetailModel];
    [_view_2 setFrame:CGRectMake(0, CGRectGetMaxY(_view_1.frame) + 10, _view_2.frame.size.width, _view_2.frame.size.height)];
    
    [_view_3 setViewData:_courseRecordDetailModel];
    [_view_3 setFrame:CGRectMake(0, CGRectGetMaxY(_view_2.frame) + (_view_2.frame.size.height == 0?0:10 ), _view_3.frame.size.width, _view_3.frame.size.height)];
    
    [_view_4 setViewData:_courseRecordDetailModel];
    [_view_4 setFrame:CGRectMake(0, CGRectGetMaxY(_view_3.frame) + (_view_3.frame.size.height == 0?0:10 ), _view_4.frame.size.width, _view_4.frame.size.height)];
    
    [self.backView setContentSize:CGSizeMake(ScreenWidth, ScreenHeihgt - NavHe > CGRectGetMaxY(_view_4.frame)?ScreenHeihgt - NavHe:CGRectGetMaxY(_view_4.frame))];
    
    //导航栏
    if([_courseRecordDetailModel.cgcStatus integerValue] > 1 && [_courseRecordDetailModel.crAccess integerValue] == 0 ){
        [self addCustomRightWithAction:@selector(toEvalutionVC) title:@"评价" normalImg:nil selectImg:nil];
    }else{
        self.navigationItem.rightBarButtonItems = nil;
    }
}

/**
 *  获取页面详情
 */
- (void)getViewData{
    ClassCourseViewModel *courseClassVM = [[ClassCourseViewModel alloc] init];
    [courseClassVM setBlockWithReturnBlock:^(id returnValue) {
        _courseRecordDetailModel = [CourseRecordDetailModel mj_objectWithKeyValues:returnValue[INTERFACE_INFO]];
        [self dismissSVProgress];
        [self setViewData];
    } WithErrorBlock:^(id errorCode) {
        [self showSVProgressFailed:@"服务器错误"];
    } WithFailureBlock:^{
        [self showSVProgressFailed:@"网络错误"];
    }];
    [self showSvprogress:@"加载数据.."];
    [courseClassVM getCourseRecordDetail:_myClassRecord.crId];
}

- (void)toEvalutionVC{
    EvaluationViewController *evalutaionVC = [[EvaluationViewController alloc] init];
    evalutaionVC.delegate = self;
    evalutaionVC.courseRecordDetail = _courseRecordDetailModel;
    [self.navigationController pushViewController:evalutaionVC animated:YES];
}
- (void)finishEvaluation:(NSNumber *)crAceess detail:(NSString *)detail{
    _courseRecordDetailModel.crAccess = crAceess;
    _courseRecordDetailModel.crAccessContent = detail;
    [self setViewData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
